/*
 *说明：时间策略 增加/修改脚本
 *
 *@author liuxun 2012-03-20
*/

var opeForm;
var operationType;

$(function(){

	opeForm=$('#opeForm');
	operationType = $('#operationType').val();

	if (operationType == 0) {
		opeForm.url = 'D_TIME_POLICY!doInsert.do';

	} else if(operationType == 1){
		opeForm.url = 'D_TIME_POLICY!doUpdate.do';

	} 

	$('#okBtn').click(doOk);
	$('#cancelBtn').click(closeWin);
});

function KeyPress(objTR){	//只允许录入数据字符 0-7
    var txtval=objTR.value; 
    var l=objTR.value.length;
    var key = event.keyCode;
    if(key <= 48||key > 55){ 
        event.keyCode = 0;
    }
}

//保存按钮操作
function doOk() {

	var validateResult = opeForm.form('validate');

	if (!validateResult){
		showInfoWin('请正确填写信息!');
		return;
	}
	
	var start_date = $('#start_date').val();
	var end_date = $('#end_date').val();

	
	var start_time = $('#start_time').val();
	var end_time = $('#end_time').val();
	if (end_time.length !=0  && start_time.length != 0) {
		if (end_time <= start_time) {
			showInfoWin('结束时间必须大于开始时间！');
			return;
		}
	}
	
	var week = $("input:checked").val();
	if(week == 'undefined'){
		showInfoWin('必须选定执行的星期！');
		return;
	}

	var options = { 
		url: opeForm.url,
		type: 'post',
		success: function(data){
			getOpenerWin().afterOK();

		    if (operationType == '0') {
				showInfoWin('操作成功!', refreshWin);

			} else {
				showInfoWin('操作成功!', function() {window.close();});
			}
		}
	};

	opeForm.ajaxSubmit(options);
}
